<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }
        html,
        body,
        .home {
            width: 100%;
            height: 100%;
            border: 1px solid black;
            overflow: hidden;
            box-sizing: border-box;
        }
        .box {
            width: 100%;
            height: 80%;
            position: relative;
            overflow: auto;
        }
        #list {
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
        }
        #message {
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        .btns {
            width: 100%;
            height: 20%;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }
        #found,
        #my {
            width: 50px;
            height: 50px;
            text-align: center;
            line-height: 50px;
            border-radius: 50%;
        }
        .active {
            background-color: skyblue;
        }
        .sav {
            width: 80%;
            height: 100px;
            line-height: 50px;
            margin: 15px;
            padding: 10px;
            border: 1px solid black;
        }
        #tianjia {
            z-index: 999;
        }
        .nav {
            margin-top: 40px;
            width: 100%;
            height: 75px;
            display: flex;
        }
        #title {
            width: 20%;
            display: inline-block;
            height: 75px;
            border: 1px solid black;
            margin-left: 20px;
            text-align: center;
            line-height: 75px;
        }
        #user {
            width: 60%;
            display: inline-block;

            height: 75px;
            border: 1px solid black;
            margin-left: 20px;
            text-align: center;
            line-height: 75px;
        }
        #update {
            width: 87%;
            height: 50px;
            border: 1px solid black;
            text-align: center;
            line-height: 50px;
            margin-left: 15px;
        }
    </style>
    <body>
        <div class="home">
            <button id="tianjia">添加心情</button>
            <div class="box">
                <div id="list"></div>
                <div id="message">
                    <div class="nav">
                        <div id="title">用户名</div>
                        <div id="user"></div>
                    </div>
                    <br />
                    <div id="update">
                        修改密码
                    </div>
                </div>
            </div>
            <div class="btns">
                <span id="found" class="active">发现</span>
                <span id="my">我的</span>
            </div>
        </div>
    </body>
    <script src="./axios.js"></script>
    <script>
        axios.get('/homelist').then(res => {
            // console.log(res.data);
            list.innerHTML += res.data.map((item, index) => {
                return `  <div class="sav"><h2>${item.user}</h2>
                    <div>${item.text}</div>
                    </div>`;
            });
        });
        user.innerHTML = localStorage.user;
        found.onclick = () => {
            tianjia.style.display = 'block';
            message.style.display = 'none';
            list.style.display = 'block';
            found.className = 'active';
            my.className = '';
        };
        my.onclick = () => {
            tianjia.style.display = 'none';
            list.style.display = 'none';
            message.style.display = 'block';
            my.className = 'active';
            found.className = '';
        };
        // let add = document.querySelector('#add');
        tianjia.onclick = function() {
            location.href = '/add';
        };
        update.onclick = () => {
            location.href = '/update';
        };
    </script>
</html>
